package summary;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/10 14:33
 * https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/
 */
public class Title589 {

    class Node {
        int val;

        List<Node> children;

        public Node() {
        }

        public Node(int val) {
            this.val = val;
        }

        public Node(int val, List<Node> children) {
            this.val = val;
            this.children = children;
        }

    }

    public List<Integer> preorder(Node root) {
        List<Integer> result = new ArrayList<>();
        traversal(root, result);
        return result;
    }

    private void traversal(Node root, List<Integer> result) {
        if (root != null) {
            result.add(root.val);
            for (Node node: root.children) {
                traversal(node, result);
            }
        }
    }

    public static void main(String[] args) {

    }
}
